//
//  ZGLNavgationController.m
//  ZeegingLottery
//
//  Created by 蒂埃里 on 2018/3/29.
//  Copyright © 2018年 蒂埃里. All rights reserved.
//

#import "ZGLNavgationController.h"

@interface ZGLNavgationController ()

@end

@implementation ZGLNavgationController

+ (void)initialize{
    
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:19]; // 字体大小
    attrs[NSForegroundColorAttributeName] = [UIColor whiteColor]; // 颜色
    
    UINavigationBar *naviBar = [UINavigationBar appearance];
    [naviBar setTitleTextAttributes:attrs];
    naviBar.barTintColor = sRGBHexAlpha(0xDC1D1D, 1.0);
    [naviBar setTintColor:[UIColor whiteColor]];

    
    // 解决iOS11界面缩放后导航栏空出状态栏的空隙的问题 方法1
//    [naviBar setBackgroundImage:[UIImage imageNamed:@"img_titlebar_red_plus"] forBarMetrics:UIBarMetricsDefault];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    // 解决iOS11界面缩放后导航栏空出状态栏的空隙的问题 方法2
    if (@available(iOS 11, *)) { // xcode9新特性 可以这样判断，xcode9以下只能用UIDevice systemVersion 来判断
        UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
        CGFloat statusH = CGRectGetHeight(statusBar.frame);
        for (UIView *view in self.navigationBar.subviews) {
            if ([NSStringFromClass([view class]) isEqualToString:@"_UIBarBackground"]) {
                CGRect frame = view.frame;
                frame.size.height = 44 + statusH;
                frame.origin.y = -statusH;
                view.frame = frame;
            }
        }
    }
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    if (self.childViewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
}

@end
